var cultureInfoString;
function TwoTierCheckBoxList_OpenFolder(id){
var div1=getElementByIdFromDocument(id+"-close");
var div2=getElementByIdFromDocument(id+"-open");
if(div1!=null&&div2!=null){
div1.style.display="none";
div2.style.display="";
}
}
function TwoTierCheckBoxList_CloseFolder(id){
var div1=getElementByIdFromDocument(id+"-open");
var div2=getElementByIdFromDocument(id+"-close");
if(div1!=null&&div2!=null){
div1.style.display="none";
div2.style.display="";
}
}
function TwoTierCheckBoxList_Highlight(id,categoryHighlight){
var div1=getElementByIdFromDocument(id+"-close");
var div2=getElementByIdFromDocument(id+"-expandTitle");
var highlightColor="#FFFBC6";
if(div1!=null&&div2!=null){
if(categoryHighlight)
{
div1.style.backgroundColor=highlightColor;
div2.style.backgroundColor=highlightColor;
}
else
{
div1.style.backgroundColor="";
div2.style.backgroundColor="";
}
}
}
function TwoTierCheckBoxList_SecondCategoryAlert(id,moreThanTwo){
var div=getElementByIdFromDocument("alertSecondCategory_"+id);
if(div!=null)
{
if(moreThanTwo)
{
div.style.display="block";
}
else
{
div.style.display="none";
}
}
}
function TwoTierCheckBoxList_Debug(text){
var div=document.getElementById("debug");
if(div!=null)div.innerHTML+=text+"<br/>";
}
function strCompare_UniCode(str1,str2){
var minLength;
str1=str1.toLowerCase();
str2=str2.toLowerCase();
if(str1.length<str2.length)minLength=str1.length;else minLength=str2.length;
for(var i=0;i<minLength-1;i++)
{
if(str1.charCodeAt(i)==str2.charCodeAt(i))continue;
return(mapUnicodeChar(str1.charCodeAt(i))>mapUnicodeChar(str2.charCodeAt(i)));
}
return(str1.length>str2.length);
}
function mapUnicodeChar(chrCode)
{
var retval;
switch(chrCode)
{
case 224:retval=97.1;break;
case 225:retval=97.2;break;
case 226:retval=97.3;break;
case 228:retval=97.4;break;
case 229:retval=97.5;break;
case 230:retval=97.7;break;
case 231:retval=99.5;break;
case 232:retval=100.3;break;
case 233:retval=100.5;break;
case 234:retval=100.7;break;
case 244:retval=110.3;break;
case 246:retval=110.5;break;
case 214:retval=110.5;break;
case 252:retval=117.5;break;
default:retval=chrCode;break;
}
if(cultureInfoString=="sv-se"||cultureInfoString=="fi-fi")
{
switch(chrCode)
{
case 229:retval=122.2;break;
case 228:retval=122.4;break;
case 246:retval=122.6;break;
}
}
else if(cultureInfoString=="nb-no"||cultureInfoString=="da-dk")
{
switch(chrCode)
{
case 230:retval=122.2;break;
case 248:retval=122.4;break;
case 229:retval=122.6;break;
}
}
return retval;
}
function TwoTierCheckBoxList_AddEvent(element,eventName,eventHandler){
if(element.attachEvent!=null){
element.attachEvent('on'+eventName,eventHandler);
}
else if(element.addEventListener!=null){
element.addEventListener(eventName,eventHandler,false);
}
else{
if(element[eventName+"Handlers"]==null){
element[eventName+"Handlers"]=[];
if(element["on"+eventName]!=null){
element[eventName+"Handlers"].push(element["on"+eventName]);
}
element["on"+eventName]=new Function("e","for ( var i = 0; i < this."+eventName+"Handlers.length; i++ ) this."+eventName+"Handlers[ i ]( e );");
}
element[eventName+"Handlers"].push(eventHandler);
}
}
function getElementByIdFromDocument(id){
return document.getElementById(id);
}
function getAbsoluteOffsetTop(id){
var result=0;
var ancestor=getElementByIdFromDocument(id);
while(ancestor!=null){
result+=ancestor.offsetTop;
ancestor=ancestor.offsetParent;
}
return result;
}
function TwoTierCheckBoxList(name,folders,items){
this.name=name;
this.folders=new Array();
this.items=new Array();
this.validators=new Array();
this.changeEventHandlers=new Array();
this.errorEventHandlers=new Array();
this.itemsDictionary=null;
this.applyAlertSecondCatSelected=false;
this.highlightSelectedItem=false;
if(window[name]==null)window[name]=this;
for(var i=0;i<folders.length;i++)if(folders[i]!=null)this.folders.push(new TwoTierCheckBoxList_Folder(this.name,this.nextFolderID(),folders[i]));
for(var i=0;i<items.length;i++)if(items[i]!=null)this.items.push(new TwoTierCheckBoxList_Item(this.name,null,this.nextItemID(),items[i]));
}
TwoTierCheckBoxList.prototype.nextFolderID=function(){
if(this.folderCnt==null)this.folderCnt=0;
return this.name+"-"+this.folderCnt++;
}
TwoTierCheckBoxList.prototype.nextItemID=function(){
if(this.itemCnt==null)this.itemCnt=0;
return this.name+"--"+this.itemCnt++;
}
TwoTierCheckBoxList.prototype.render=function(divID){
if(divID!=null){
this.divID=divID;
}
if(this.divID==null)return;
var html=new Array();
if(this.folderToRender!=null){
for(var i=0;i<this.folderToRender.items.length;i++)this.renderItem(this.folderToRender.items[i],html);
}
else{
if(this.renderItemsFirst){
for(var i=0;i<this.items.length;i++)this.renderItem(this.items[i],html);
for(var i=0;i<this.folders.length;i++)this.renderFolder(this.folders[i],html);
}
else{
for(var i=0;i<this.folders.length;i++)this.renderFolder(this.folders[i],html);
for(var i=0;i<this.items.length;i++)this.renderItem(this.items[i],html);
}
}
this.element=document.getElementById(this.divID);
this.element.innerHTML=html.join("");
this.attachEvents();
}
TwoTierCheckBoxList.prototype.iterateFolders=function(callback,result){
for(var i=0;i<this.folders.length;i++){
if(callback(this.folders[i],result))return;
}
}
TwoTierCheckBoxList.prototype.iterateItems=function(callback,result){
for(var i=0;i<this.folders.length;i++){
var folder=this.folders[i];
for(var j=0;j<folder.items.length;j++){
if(callback(folder.items[j],result))return;
}
}
for(var j=0;j<this.items.length;j++){
if(callback(this.items[j],result))return;
}
}
TwoTierCheckBoxList.prototype.getItem=function(value){
if(this.itemsDictionary==null){
var callback=function(item,result){result[item.value]=item;}
this.itemsDictionary=new Object();
this.iterateItems(callback,this.itemsDictionary);
}
return this.itemsDictionary[value];
}
TwoTierCheckBoxList.prototype.getFolderByName=function(name){
if(this.foldersDictionary==null){
var callback=function(folder,result){result[folder.name]=folder;}
this.foldersDictionary=new Object();
this.iterateFolders(callback,this.foldersDictionary);
}
return this.foldersDictionary[name];
}
TwoTierCheckBoxList.prototype.select=function(value,checked){
var item=this.getItem(value);
if(item!=null)item.select(checked);
}
TwoTierCheckBoxList.prototype.focus=function(value){
var item=this.getItem(value);
if(item!=null){
this.focusLastItem();
if(item.folder!=null)item.folder.open();
item.focus();
}
}
TwoTierCheckBoxList.prototype.focusLastItem=function(){
if(this.lastItem!=null){
var openFolder=(this.lastItem.folder!=null&&!this.lastItem.folder.isOpened());
var enabled=this.lastItem.isEnabled();
if(openFolder)this.lastItem.folder.open();
if(!enabled)this.lastItem.enable();
this.lastItem.focus();
if(!enabled)this.lastItem.disable();
if(openFolder)this.lastItem.folder.close();
}
}
TwoTierCheckBoxList.prototype.focusFirstSelectedItem=function(){
if(this.getSelection().itemCount>0){
var firstItem;
if(this.renderItemsFirst){
if(this.getSelection().items.length>0){
firstItem=this.getSelection().items[0];
}
else{
firstItem=this.getSelection().folders[0].items[0];
}
}
else{
if(this.getSelection().folders.length>0){
firstItem=this.getSelection().folders[0].items[0];
}
else{
firstItem=this.getSelection().items[0];
}
}
this.focusLastItem();
if(firstItem.folder!=null)firstItem.folder.open();
firstItem.focus();
}
}
TwoTierCheckBoxList.prototype.getSelection=function(){
if(this.selection==null){
this.selection=new TwoTierCheckBoxList_Selection();
var moreThanTwo=false;
var countCategoryChosen=0;
for(var i=0;i<this.folders.length;i++){
var folder=this.folders[i];
var selectedFolder=null;
var itemsCheck=false;
var hasItemSelected=false;
folder.selectedItemsCount=0;
for(var j=0;j<folder.items.length;j++){
var item=folder.items[j];
if(item.isSelected()){
if(selectedFolder==null){
selectedFolder=new TwoTierCheckBoxList_Folder(this.name,folder.id,[folder.name,[],folder.folderInfo]);
this.selection.folders.push(selectedFolder);
}
itemsCheck=true;
selectedFolder.items.push(item);
folder.selectedItemsCount++;
this.selection.itemCount++;
hasItemSelected=true;
}
}
if(this.applyAlertSecondCatSelected&&hasItemSelected)
countCategoryChosen+=1;
if(this.highlightSelectedItem)
TwoTierCheckBoxList_Highlight(folder.id,itemsCheck);
}
for(var i=0;i<this.items.length;i++){
var item=this.items[i];
if(item.isSelected()){
this.selection.items.push(item);
this.selection.itemCount++;
}
}
if(this.applyAlertSecondCatSelected)
{
if(countCategoryChosen>1)
{
moreThanTwo=true;
}
TwoTierCheckBoxList_SecondCategoryAlert(this.name,moreThanTwo);
}
}
return this.selection;
}
TwoTierCheckBoxList.prototype.isSelected=function(){
for(var i=0;i<this.folders.length;i++){
var folder=this.folders[i];
for(var j=0;j<folder.items.length;j++){
if(folder.items[j].isSelected())return true;
}
}
for(var i=0;i<this.items.length;i++){
if(this.items[i].isSelected())return true;
}
return false;
}
TwoTierCheckBoxList.prototype.getValue=function(){
if(this.value==null){
var selectedValues=new Array();
for(var i=0;i<this.getSelection().folders.length;i++){
for(var j=0;j<this.getSelection().folders[i].items.length;j++){
selectedValues.push(this.getSelection().folders[i].items[j].value);
}
}
for(var i=0;i<this.getSelection().items.length;i++){
selectedValues.push(this.getSelection().items[i].value);
}
this.value=selectedValues.join(",")
}
return this.value;
}
TwoTierCheckBoxList.prototype.attachEvents=function(){
if(!this.disabled){
var checkBoxes=document.forms[this.formID].elements[this.name+"_values"];
var k=0;
var checkBox;
var onClick=function(){
var checkBoxList=window[this.checkBoxListName];
checkBoxList.selection=null;
checkBoxList.value=null;
if(checkBoxList.validate())checkBoxList.onChange(this.getItem());
else this.checked=false;
}
if(this.folderToRender!=null){
var getItem=function(){return window[this.checkBoxListName].folderToRender.items[this.itemIndex];}
for(var j=0;j<this.folderToRender.items.length;j++){
checkBox=(checkBoxes.length!=null)?checkBoxes[k++]:checkBoxes;
this.folderToRender.items[j].checkBox=checkBox;
checkBox.itemIndex=j;
checkBox.checkBoxListName=this.name
checkBox.getItem=getItem;
checkBox.onclick=onClick;
}
}
else{
var getItem1=function(){return window[this.checkBoxListName].folders[this.folderIndex].items[this.itemIndex];}
var getItem2=function(){return window[this.checkBoxListName].items[this.itemIndex];}
if(this.renderItemsFirst){
for(var j=0;j<this.items.length;j++){
checkBox=(checkBoxes.length!=null)?checkBoxes[k++]:checkBoxes;
this.items[j].checkBox=checkBox;
checkBox.itemIndex=j;
checkBox.checkBoxListName=this.name
checkBox.getItem=getItem2;
checkBox.onclick=onClick;
}
}
for(var i=0;i<this.folders.length;i++){
var folder=this.folders[i];
for(var j=0;j<folder.items.length;j++){
checkBox=(checkBoxes.length!=null)?checkBoxes[k++]:checkBoxes;
folder.items[j].checkBox=checkBox;
checkBox.folderIndex=i;
checkBox.itemIndex=j;
checkBox.checkBoxListName=this.name
checkBox.getItem=getItem1;
checkBox.onclick=onClick;
}
}
if(!this.renderItemsFirst){
for(var j=0;j<this.items.length;j++){
checkBox=(checkBoxes.length!=null)?checkBoxes[k++]:checkBoxes;
this.items[j].checkBox=checkBox;
checkBox.itemIndex=j;
checkBox.checkBoxListName=this.name
checkBox.getItem=getItem2;
checkBox.onclick=onClick;
}
}
}
}
}
TwoTierCheckBoxList.prototype.addFolders=function(folders){
var modified=false;
if(folders==undefined)return false;
for(var i=0;i<folders.length;i++){
if(folders[i]==null)continue;
var folderName=folders[i][0];
var items=folders[i][1];
var folder=null;
for(var ii=0;ii<this.folders.length;ii++){
if(this.folders[ii].name.toLowerCase()==folderName.toLowerCase()){
folder=this.folders[ii];
for(var j=0;j<items.length;j++){
if(items[j]==null)continue;
var itemName=items[j][1];
var item=null;
for(var jj=0;jj<folder.items.length;jj++){
if(folder.items[jj].name.toLowerCase()==itemName.toLowerCase()){
item=folder.items[jj];
break;
}
if(this.sortItems&&strCompare_UniCode(folder.items[jj].name,itemName)){
item=new TwoTierCheckBoxList_Item(this.name,folder,folder.nextItemID(),items[j]);
folder.items.splice(jj,0,item);
modified=true;
break;
}
}
if(item==null){
item=new TwoTierCheckBoxList_Item(this.name,folder,folder.nextItemID(),items[j]);
folder.items.push(item);
modified=true;
}
}
break;
}
if(this.sortFolders&&strCompare_UniCode(this.folders[ii].name,folderName)){
folder=new TwoTierCheckBoxList_Folder(this.name,this.nextFolderID(),folders[i]);
this.folders.splice(ii,0,folder);
modified=true;
break;
}
}
if(folder==null){
folder=new TwoTierCheckBoxList_Folder(this.name,this.nextFolderID(),folders[i]);
this.folders.push(folder);
modified=true;
}
}
if(modified)this.itemsDictionary=null;
return modified;
}
TwoTierCheckBoxList.prototype.addFoldersOptimized=function(folders){
var modified=false;
if(folders==undefined)return false;
for(var i=0;i<folders.length;i++){
if(folders[i]==null)continue;
var folderName=folders[i][0];
var items=folders[i][1];
var folder=null;
folder=this.getFolderByName(folderName);
if(folder!=null){
for(var j=0;j<items.length;j++){
if(items[j]==null)continue;
var itemValue=items[j][0]
var itemName=items[j][1];
var item=null;
item=this.getItem(itemValue);
if(item==null){
item=new TwoTierCheckBoxList_Item(this.name,folder,folder.nextItemID(),items[j]);
this.itemsDictionary[itemValue]=item;
modified=true;
var indexForNewItem=-1;
if(this.sortItems){
var low=0;
var high=folder.items.length-1;
while(low!=high){
var median=(low+high)>>>1;
var medianItemName=folder.items[median].name;
if(strCompare_UniCode(itemName,medianItemName)){
low=median+1;
}
else{
high=median;
}
}
if(low==folder.items.length-1&&strCompare_UniCode(itemName,folder.items[low].name)){
indexForNewItem=low+1;
}
else{
indexForNewItem=low;
}
}
if(indexForNewItem!=-1&&indexForNewItem<folder.items.length){
folder.items.splice(indexForNewItem,0,item);
}
else{
folder.items.push(item);
}
}
}
}
else{
folder=new TwoTierCheckBoxList_Folder(this.name,this.nextFolderID(),folders[i]);
var indexForNewFolder=-1;
if(this.sortFolders){
for(var ii=0;ii<this.folders.length;ii++){
if(strCompare_UniCode(this.folders[ii].name,folderName)){
indexForNewFolder=ii;
break;
}
}
}
if(indexForNewFolder!=-1){
this.folders.splice(this.folders.length,0,folder);
}
else{
this.folders.push(folder);
}
modified=true;
this.foldersDictionary[folderName]=folder;
}
}
return modified;
}
TwoTierCheckBoxList.prototype.addItems=function(items){
var modified=false;
if(items==undefined)return false;
for(var j=0;j<items.length;j++){
if(items[j]==null)continue;
var itemName=items[j][1];
var item=null;
for(var jj=0;jj<this.items.length;jj++){
if(this.items[jj].name.toLowerCase()==itemName.toLowerCase()){
item=this.items[jj];
break;
}
if(this.sortItems&&strCompare_UniCode(this.items[jj].name,itemName)){
item=new TwoTierCheckBoxList_Item(this.name,null,this.nextItemID(),items[j]);
this.items.splice(jj,0,item);
modified=true;
break;
}
}
if(item==null){
item=new TwoTierCheckBoxList_Item(this.name,null,this.nextItemID(),items[j]);
this.items.push(item);
modified=true;
}
}
if(modified)this.itemsDictionary=null;
return modified;
}
TwoTierCheckBoxList.prototype.removeFolders=function(folders){
var modified=false;
var selectionChanged=false;
if(folders==undefined)return false;
for(var i=0;i<folders.length;i++){
var folderName=folders[i][0];
var items=folders[i][1];
for(var ii=0;ii<this.folders.length;ii++){
if(this.sortFolders&&strCompare_UniCode(this.folders[ii].name,folderName))break;
if(this.folders[ii].name.toLowerCase()==folderName.toLowerCase()){
var folder=this.folders[ii];
for(var j=0;j<items.length;j++){
if(items[j]==undefined)break;
var itemName=items[j][1];
for(var jj=0;jj<folder.items.length;jj++){
if(this.sortItems&&strCompare_UniCode(folder.items[jj].name,itemName))break;
if(folder.items[jj].name.toLowerCase()==itemName.toLowerCase()){
selectionChanged=selectionChanged||folder.items[jj].isSelected();
folder.items[jj].folder=null;
folder.items.splice(jj,1);
modified=true;
break;
}
}
}
if(folder.items.length==0){
this.folders.splice(ii,1);
modified=true;
}
break;
}
}
}
if(selectionChanged){
this.selection=null;
this.value=null;
this.onChange();
}
if(modified)this.itemsDictionary=null;
return modified;
}
TwoTierCheckBoxList.prototype.removeItems=function(items){
var modified=false;
var selectionChanged=false;
if(items==undefined)return false;
for(var j=0;j<items.length;j++){
var itemName=items[j][1];
for(var jj=0;jj<this.items.length;jj++){
if(this.sortItems&&strCompare_UniCode(this.items[jj].name,itemName))break;
if(this.items[jj].name.toLowerCase()==itemName.toLowerCase()){
selectionChanged=selectionChanged||this.items[jj].isSelected();
this.items.splice(jj,1);
modified=true;
break;
}
}
}
if(selectionChanged){
this.selection=null;
this.value=null;
this.onChange();
}
if(modified)this.itemsDictionary=null;
return modified;
}
TwoTierCheckBoxList.prototype.clear=function(){
for(var i=0;i<this.folders.length;i++){
for(var j=0;j<this.folders[i].items.length;j++){
this.folders[i].items[j].folder=null;
}
}
this.itemsDictionary=null;
this.folders=new Array();
this.items=new Array();
}
TwoTierCheckBoxList.prototype.clearSelection=function(){
var selectedValues=this.getValue().split(/,/g);
for(var i=0;i<selectedValues.length;i++)this.select(selectedValues[i],false);
}
TwoTierCheckBoxList.prototype.addValidator=function(validator){
this.validators.push(validator);
}
TwoTierCheckBoxList.prototype.validate=function(){
for(var i=0;i<this.validators.length;i++){
if(!this.validators[i].validate(this)){
this.onError(this.validators[i].errorMessage);
this.selection=null;
return false;
}
}
return true;
}
TwoTierCheckBoxList.prototype.addChangeEventHandler=function(eventHandler){
this.changeEventHandlers.push(eventHandler);
}
TwoTierCheckBoxList.prototype.onChange=function(item){
for(var i=0;i<this.changeEventHandlers.length;i++){
var handler=this.changeEventHandlers[i];
if(typeof(handler)=="object"){
handler.execute(this,item);
}
else{
handler(this,item);
}
}
}
TwoTierCheckBoxList.prototype.addErrorEventHandler=function(eventHandler){
this.errorEventHandlers.push(eventHandler);
}
TwoTierCheckBoxList.prototype.onError=function(errorMessage){
if(this.errorEventHandlers.length>0){
for(var i=0;i<this.errorEventHandlers.length;i++){
this.errorEventHandlers[i](this,errorMessage);
}
}
else{
alert(errorMessage);
}
}
TwoTierCheckBoxList.prototype.onItemSelected=function(item){
this.selection=null;
this.value=null;
if(this.validate()){
this.onChange(item);
if(item.isSelected()&&this.openFolderOnSelect&&item.folder!=null){
item.folder.open();
}
return true;
}
return false;
}
TwoTierCheckBoxList.prototype.disabled=false;
TwoTierCheckBoxList.prototype.setDisabled=function(value){
if(this.disabled!=value){
this.disabled=(value==true);
if(this.disabled)this.clearSelection();
this.render();
}
}
TwoTierCheckBoxList.prototype.folderFormatString="<div id=\"{Folder.ID}-close\" class=\"folder\"  onClick=\"TwoTierCheckBoxList_OpenFolder('{Folder.ID}');\"><div class=\"expand\"><code>+</code></div><div id=\"{Folder.ID}-collapseTitle\" class=\"cbl_folder\">{Folder.Name}</div></div>\n<div id=\"{Folder.ID}-open\" class=\"folder\" style=\"display:none;\"><div onClick=\"TwoTierCheckBoxList_CloseFolder('{Folder.ID}');\"><div class=\"collapse\"><code>-</code></div><div id=\"{Folder.ID}-expandTitle\" class=\"cbl_item\">{Folder.Name}</div></div>{Folder.Items}</div>";
TwoTierCheckBoxList.prototype.itemFormatString="<div class=\"item\">{Checkbox}<div class=\"cbl_item\"><label for=\"{Item.ID}\">{Item.Name}</label></div></div>\n";
TwoTierCheckBoxList.prototype.openFolderOnSelect=false;
TwoTierCheckBoxList.prototype.renderItemsFirst=false;
TwoTierCheckBoxList.prototype.sortFolders=true;
TwoTierCheckBoxList.prototype.sortItems=true;
TwoTierCheckBoxList.prototype.folderToRender=null;
TwoTierCheckBoxList.prototype.formID=0;
TwoTierCheckBoxList.prototype.renderFolder=function(folder,html){
if(this.folderFormatFunction==null){
var code="html.push(\""+this.folderFormatString.replace(/"/g,"\\\"").replace(/\n/g,"\\n")+"\");";
code=code.replace(/\{Name\}/g,"\");html.push(\""+this.name+"\");html.push(\"");
code=code.replace(/\{Folder\.ID\}/g,"\");html.push(folder.id);html.push(\"");
code=code.replace(/\{Folder\.Name\}/g,"\");html.push(folder.name);html.push(\"");
code=code.replace(/\{Folder\.Items\}/g,"\");for(var i=0;i<folder.items.length;i++)this.renderItem(folder.items[i],html);html.push(\"");
this.folderFormatFunction=new Function("folder","html",code);
}
if(folder.items.length>0){
this.folderFormatFunction(folder,html);
}
}
TwoTierCheckBoxList.prototype.renderItem=function(item,html){
this.lastItem=item;
if(this.itemFormatFunction==null){
var code="html.push(\""+this.itemFormatString.replace(/"/g,"\\\"").replace(/\n/g,"\\n")+"\");";
code=code.replace(/\{Checkbox}/g,"<input type=\\\"checkbox\\\" name=\\\"{Name}_values\\\" value=\\\"{Item.Value}\\\" id=\\\"{Item.ID}\\\"{Disabled}>");
code=code.replace(/\{Name\}/g,"\");html.push(\""+this.name+"\");html.push(\"");
code=code.replace(/\{Item\.ID\}/g,"\");html.push(item.id);html.push(\"");
code=code.replace(/\{Item\.Name\}/g,"\");html.push(item.name);html.push(\"");
code=code.replace(/\{Item\.Value\}/g,"\");html.push(item.value);html.push(\"");
code=code.replace(/\{Disabled\}/g,"\");html.push( this.disabled ? \" disabled='Yes'\" : \"\" );html.push(\"");
this.itemFormatFunction=new Function("item","html",code);
}
this.itemFormatFunction(item,html);
}
TwoTierCheckBoxList.prototype.getSearchExpression=function(text){
if(text==null||text.length==0)return null;
if(text.length<3)return new RegExp("^("+text+")","ig");
return new RegExp("("+text+")","ig");
}
TwoTierCheckBoxList.prototype.find=function(text){
var result=new Array();
result.regularExpression=this.getSearchExpression(text);
if(result.regularExpression!=null){
result.names=new Object();
result.duplicates=new Object();
var callback=function(item,result){
if(!item.isSelected()&&item.isEnabled()&&item.name.match(result.regularExpression)){
result.push(item);
result.duplicates[item.name]=(result.names[item.name]==true);
result.names[item.name]=true;
}
}
this.iterateItems(callback,result);
result.sort(function(a,b){
if(strCompare_UniCode(a.name,b.name))return 1;
if(strCompare_UniCode(b.name,a.name))return-1;
if(a.folder!=null&&b.folder!=null){
if(strCompare_UniCode(a.folder.name,b.folder.name))return 1;
if(strCompare_UniCode(b.folder.name,a.folder.name))return-1;
}
return 0;
});
}
return result;
}
TwoTierCheckBoxList.prototype.openSelectedFolders=function(){
this.iterateFolders(function(folder){if(folder.selectedItemsCount>0)folder.open();});
}
TwoTierCheckBoxList.prototype.scrollItemToTop=function(item){
var myDiv=getElementByIdFromDocument(this.divID);
var checkBoxListOffsetTop=getAbsoluteOffsetTop(this.divID);
var itemOffsetTop=getAbsoluteOffsetTop(item.id);
var relativeItemOffset=itemOffsetTop-checkBoxListOffsetTop;
myDiv.scrollTop=relativeItemOffset;
}
TwoTierCheckBoxList.prototype.setFlagItemHighlightAndAlertSecondCatSelected=function(isHighlight,isAlertNeeded){
this.applyAlertSecondCatSelected=isHighlight;
this.highlightSelectedItem=isAlertNeeded;
}
function TwoTierCheckBoxList_Folder(checkBoxListName,id,folder){
this.checkBoxListName=checkBoxListName;
this.id=id;
this.name=folder[0];
this.items=new Array();
for(var i=0;i<folder[1].length;i++)if(folder[1][i]!=null)this.items.push(new TwoTierCheckBoxList_Item(checkBoxListName,this,this.nextItemID(),folder[1][i]));
if(folder.length>2)this.folderInfo=folder[2];
}
TwoTierCheckBoxList_Folder.prototype.nextItemID=function(){
if(this.itemCnt==null)this.itemCnt=0;
return this.id+"-"+this.itemCnt++;
}
TwoTierCheckBoxList_Folder.prototype.isOpened=function(){
var element=document.getElementById(this.id+"-open");
return(element!=null&&element.style.display=="");
}
TwoTierCheckBoxList_Folder.prototype.open=function(){
TwoTierCheckBoxList_OpenFolder(this.id);
}
TwoTierCheckBoxList_Folder.prototype.close=function(){
TwoTierCheckBoxList_CloseFolder(this.id);
}
TwoTierCheckBoxList_Folder.copy=function(folders){
var result=new Array();
for(var i=0;i<folders.length;i++){
var newFolder=[folders[i][0],TwoTierCheckBoxList_Item.copy(folders[i][1])];
if(folders[i].length>2)newFolder.push(folders[i][2]);
result.push(newFolder);
}
return result;
}
TwoTierCheckBoxList_Folder.add=function(existingFolders,foldersToAdd){
for(var i=0;i<foldersToAdd.length;i++){
var folderName=foldersToAdd[i][0];
var folder=null;
for(var j=0;j<existingFolders.length;j++){
if(existingFolders[j][0].toLowerCase()==folderName.toLowerCase()){
folder=existingFolders[j];
TwoTierCheckBoxList_Item.add(existingFolders[j][1],foldersToAdd[i][1])
break;
}
if(strCompare_UniCode(existingFolders[j][0],folderName)){
folder=[folderName,TwoTierCheckBoxList_Item.copy(foldersToAdd[i][1])];
existingFolders.splice(j,0,folder);
break;
}
}
if(folder==null){
var newFolder=[folderName,TwoTierCheckBoxList_Item.copy(foldersToAdd[i][1])];
if(foldersToAdd[i].length>2)newFolder.push(foldersToAdd[i][2]);
existingFolders.push(newFolder);
}
}
}
TwoTierCheckBoxList_Folder.remove=function(existingFolders,foldersToRemove){
for(var i=0;i<foldersToRemove.length;i++){
var folderName=foldersToRemove[i][0];
for(var j=0;j<existingFolders.length;j++){
if(strCompare_UniCode(existingFolders[j][0],folderName))break;
if(existingFolders[j][0].toLowerCase()==folderName.toLowerCase()){
TwoTierCheckBoxList_Item.remove(existingFolders[j][1],foldersToRemove[i][1]);
if(existingFolders[j][1].length==0)existingFolders.splice(j,1);
break;
}
}
}
}
TwoTierCheckBoxList_Folder.prototype.disable=function(){
for(var i=0;i<this.items.length;i++){
if(!this.items[i].isSelected()){
this.items[i].disable();
}
}
}
TwoTierCheckBoxList_Folder.prototype.enable=function(){
for(var i=0;i<this.items.length;i++){
this.items[i].enable();
}
}
function TwoTierCheckBoxList_Item(checkBoxListName,folder,id,item){
this.checkBoxListName=checkBoxListName;
this.folder=folder;
this.id=id;
this.value=item[0];
this.name=item[1];
if(item.length>2)this.itemInfo=item[2];
}
TwoTierCheckBoxList_Item.prototype.getCheckBoxList=function(){return window[this.checkBoxListName];}
TwoTierCheckBoxList_Item.prototype.isSelected=function(){
if(this.checkBox==null)return false;
return this.checkBox.checked;
}
TwoTierCheckBoxList_Item.prototype.isEnabled=function(){
if(this.checkBox==null)return false;
return!this.checkBox.disabled;
}
TwoTierCheckBoxList_Item.prototype.isDisabled=function(){
if(this.checkBox!=null)return this.checkBox.disabled;
return false;
}
TwoTierCheckBoxList_Item.prototype.enable=function(){
if(this.checkBox!=null)this.checkBox.disabled=false;
}
TwoTierCheckBoxList_Item.prototype.disable=function(){
if(this.checkBox!=null)this.checkBox.disabled=true;
}
TwoTierCheckBoxList_Item.prototype.focus=function(){
if(this.checkBox!=null)this.checkBox.focus();
}
TwoTierCheckBoxList_Item.prototype.select=function(value){
if(this.checkBox!=null&&value!=this.isSelected()){
this.checkBox.checked=value;
if(!this.getCheckBoxList().onItemSelected(this))this.checkBox.checked=false;
}
}
TwoTierCheckBoxList_Item.copy=function(items){
var result=new Array();
for(var i=0;i<items.length;i++){
if(items[i]!=undefined)
{
var newItem=[items[i][0],items[i][1]];
if(items[i].length>2)newItem.push(items[i][2]);
result.push(newItem);
}
}
return result;
}
TwoTierCheckBoxList_Item.add=function(existingItems,itemsToAdd){
for(var i=0;i<itemsToAdd.length;i++){
var itemValue=itemsToAdd[i][0];
var itemName=itemsToAdd[i][1];
var item=null;
for(var j=0;j<existingItems.length;j++){
if(existingItems[j][1].toLowerCase()==itemName.toLowerCase()){
item=existingItems[j];
break;
}
if(strCompare_UniCode(existingItems[j][1],itemName)){
item=[itemValue,itemName];
existingItems.splice(j,0,item);
break;
}
}
if(item==null){
var newItem=[itemValue,itemName];
if(itemsToAdd[i].length>2)newItem.push(itemsToAdd[i][2]);
existingItems.push(newItem);
}
}
}
TwoTierCheckBoxList_Item.remove=function(existingItems,itemsToRemove){
for(var i=0;i<itemsToRemove.length;i++){
var itemName=itemsToRemove[i][1];
for(var j=0;j<existingItems.length;j++){
if(existingItems[j][1]>itemName)break;
if(existingItems[j][1]==itemName){
existingItems.splice(j,1);
break;
}
}
}
}
function TwoTierCheckBoxList_Selection(){
this.folders=new Array();
this.items=new Array();
this.itemCount=0;
}
TwoTierCheckBoxList_Selection.prototype.merge=function(selection){
for(var i=0;i<selection.folders.length;i++){
var folder=null;
var folder1=selection.folders[i];
for(var ii=0;ii<this.folders.length;ii++){
var folder2=this.folders[ii];
if(folder2.name==folder1.name){
folder=folder2;
break;
}
else if(strCompare_UniCode(folder2.name,folder1.name)){
folder=new TwoTierCheckBoxList_Folder(folder1.checkBoxListName,folder1.id,[folder1.name,[],folder1.folderInfo]);
this.folders.splice(ii,0,folder);
break;
}
}
if(folder==null){
folder=new TwoTierCheckBoxList_Folder(folder1.checkBoxListName,folder1.id,[folder1.name,[],folder1.folderInfo]);
this.folders.push(folder);
}
for(var j=0;j<folder1.items.length;j++){
var item=null;
var item1=folder1.items[j];
for(var jj=0;jj<folder.items.length;jj++){
var item2=folder.items[jj];
if(item2.name==item1.name){
item=item2;
break;
}
else if(strCompare_UniCode(item2.name,item1.name)){
item=item1;
folder.items.splice(jj,0,item);
this.itemCount++;
break;
}
}
if(item==null){
item=item1;
folder.items.push(item);
this.itemCount++;
}
}
}
for(var j=0;j<selection.items.length;j++){
var item=null;
var item1=selection.items[j];
for(var jj=0;jj<this.items.length;jj++){
var item2=this.items[jj];
if(item2.name==item1.name){
item=item2;
break;
}
else if(strCompare_UniCode(item2.name,item1.name)){
item=item1;
this.items.splice(jj,0,item);
this.itemCount++;
break;
}
}
if(item==null){
item=item1;
this.items.push(item);
this.itemCount++;
}
}
}
function TwoTierCheckBoxList_TallyBox(divID){
this.checkBoxListNames=new Array();
this.divID=divID;
var cultureInfoStringHiddenField=document.getElementById("hfCultureInfoString");
if(cultureInfoStringHiddenField!=null&&cultureInfoStringHiddenField.value!=null)
{
cultureInfoString=cultureInfoStringHiddenField.value.toLowerCase();
}
}
TwoTierCheckBoxList_TallyBox.prototype.folderFormatString="<div class=\"folder\">\n<div class=\"header\">{Folder.Name}</div>\n{Folder.Items}</div>";
TwoTierCheckBoxList_TallyBox.prototype.itemFormatString="<div class=\"item\"><div class=\"remove\"><a href=\"javascript:{Name}.select('{Item.Value}',false);\">X</a></div>{Item.Name}</div>\n";
TwoTierCheckBoxList_TallyBox.prototype.getCheckBoxList=function(i){
return window[this.checkBoxListNames[i]];
}
TwoTierCheckBoxList_TallyBox.prototype.renderFolder=function(folder,html){
if(this.folderFormatFunction==null){
var code="var code=new Array();code.push(\""+this.folderFormatString.replace(/"/g,"\\\"").replace(/\n/g,"\\n")+"\");html.push(code.join(\"\"));";
code=code.replace(/\{Name\}/g,"\");code.push(folder.checkBoxListName);code.push(\"");
code=code.replace(/\{Folder\.Name\}/g,"\");code.push(folder.name);code.push(\"");
code=code.replace(/\{Folder\.Items\}/g,"\");for(var i=0;i<folder.items.length;i++)this.renderItem(folder.items[i],code);code.push(\"");
this.folderFormatFunction=new Function("folder","html",code);
}
this.folderFormatFunction(folder,html);
}
TwoTierCheckBoxList_TallyBox.prototype.renderItem=function(item,html){
if(this.itemFormatFunction==null){
var code="var code=new Array();code.push(\""+this.itemFormatString.replace(/"/g,"\\\"").replace(/\n/g,"\\n")+"\");html.push(code.join(\"\"));";
code=code.replace(/\{Name\}/g,"\");code.push(item.checkBoxListName);code.push(\"");
code=code.replace(/\{Item\.Name\}/g,"\");code.push(item.name);code.push(\"");
code=code.replace(/\{Item\.Value\}/g,"\");code.push(item.value);code.push(\"");
this.itemFormatFunction=new Function("item","html",code);
}
this.itemFormatFunction(item,html);
}
TwoTierCheckBoxList_TallyBox.prototype.getSelection=function(){
if(this.selection==null){
this.selection=new TwoTierCheckBoxList_Selection()
for(var i=0;i<this.checkBoxListNames.length;i++){
this.selection.merge(this.getCheckBoxList(i).getSelection());
}
}
return this.selection;
}
TwoTierCheckBoxList_TallyBox.prototype.render=function(){
var html=new Array();
for(var i=0;i<this.getSelection().folders.length;i++){
this.renderFolder(this.getSelection().folders[i],html);
}
for(var i=0;i<this.getSelection().items.length;i++){
this.renderItem(this.getSelection().items[i],html);
}
var element=document.getElementById(this.divID);
element.innerHTML=html.join("\n");
}
TwoTierCheckBoxList_TallyBox.prototype.attachEvents=function(){
var tallyBox=this;
for(var i=0;i<this.checkBoxListNames.length;i++){
this.getCheckBoxList(i).addChangeEventHandler(function(sender){tallyBox.selection=null;tallyBox.render();});
}
}
function TwoTierCheckBoxList_QuickFind(id,checkBoxListName,applyNextGen){
this.id=id;
this.checkBoxListName=checkBoxListName;
this.menu=new TwoTierCheckBoxList_QuickFind_Menu(id+".menu",id+":Menu");
this.applyNextGen=applyNextGen.toLowerCase();
}
TwoTierCheckBoxList_QuickFind.prototype.maxFindResults=10;
TwoTierCheckBoxList_QuickFind.prototype.focusSelectedItem=true;
TwoTierCheckBoxList_QuickFind.prototype.defaultText="";
TwoTierCheckBoxList_QuickFind.prototype.noMatchText="";
TwoTierCheckBoxList_QuickFind.prototype.getCheckBoxList=function(){return window[this.checkBoxListName];}
TwoTierCheckBoxList_QuickFind.prototype.getTextBox=function(){return window["txt"+this.id];}
TwoTierCheckBoxList_QuickFind.prototype.getButton=function(){return window["btn"+this.id];}
TwoTierCheckBoxList_QuickFind.prototype.getMenu=function(){return window["mnu"+this.id];}
TwoTierCheckBoxList_QuickFind.prototype.clear=function(){
this.menu.clear();
this.menu.hide();
this.getTextBox().value=this.defaultText;
if(this.applyNextGen=="false")
this.getTextBox().className="TextBox Blur";
else
this.getTextBox().className="TextBoxNextGen Blur";
this.disableButton();
}
TwoTierCheckBoxList_QuickFind.prototype.disableButton=function(){
var btn=this.getButton();
if(btn!=null&&!btn.disabled){
btn.disabled=true;
btn.className+=" Disabled";
}
}
TwoTierCheckBoxList_QuickFind.prototype.enableButton=function(){
var btn=this.getButton();
if(btn!=null&&btn.disabled){
btn.disabled=false;
btn.className=btn.className.replace(/ Disabled/ig,"");
}
}
TwoTierCheckBoxList_QuickFind.prototype.attachEvents=function(){
var code=new Array();
code.push("if(menuItem != null) {");
code.push("var item = "+this.checkBoxListName+".getItem( menuItem.value );");
code.push("item.select( true );");
if(this.focusSelectedItem){
code.push("if ( item.isSelected() ) {");
code.push("if ( item.folder != null ) item.folder.open();");
code.push(this.checkBoxListName+".scrollItemToTop(item);");
code.push("}");
}
code.push("}");
code.push(this.id+".clear();");
code.push(this.id+".getTextBox().focus();")
this.menu.onSelect=new Function("menu","menuItem",code.join(""));
code=new Array();
code.push("if ( selectedItem != null ) {");
code.push("txt"+this.id+".value = selectedItem.name;");
code.push("btn"+this.id+".selectedValue = selectedItem.value;");
code.push(this.id+".enableButton();");
code.push("}");
this.menu.focusChanged=new Function("selectedItem",code.join(""));
this.getTextBox().quickFind=this;
this.getTextBox().onmouseover=function(){this.quickFind.menu.isFocused=true;}
this.getTextBox().onmouseout=function(){this.quickFind.menu.isFocused=false;}
this.getTextBox().onkeyup=function(){if(!this.navigationMove)this.quickFind.render();}
this.getTextBox().onblur=function(){if(!this.quickFind.menu.isFocused)this.quickFind.clear();}
this.getTextBox().onfocus=function(){
this.quickFind.render();
if(this.quickFind.applyNextGen=="false")
this.className="TextBox";
else
this.className="TextBoxNextGen";
if(this.value==this.quickFind.defaultText)this.value="";
}
this.getTextBox().onkeydown=function(e){
if(e==null)e=window.event;
var code=e.keyCode?e.keyCode:e.which;
this.navigationMove=false;
switch(code){
case 38:{
if(this.quickFind.menu.isVisible()){
this.quickFind.menu.moveUp();
}
else{
this.quickFind.show();
}
this.navigationMove=true;
break;
}
case 40:{
if(this.quickFind.menu.isVisible()){
this.quickFind.menu.moveDown();
}
else{
this.quickFind.show();
}
this.navigationMove=true;
break;
}
case 27:{
if(this.quickFind.menu.isVisible()){
this.quickFind.menu.hide();
this.navigationMove=true;
}
break;
}
case 13:
case 9:{
if(this.quickFind.menu.isVisible()){
this.quickFind.menu.select();
this.navigationMove=true;
}
break;
}
}
return!this.navigationMove;
};
if(this.getButton()!=null){
this.getButton().disabled=true;
this.getButton().quickFind=this;
this.getButton().onmouseover=function(){this.quickFind.menu.isFocused=true;}
this.getButton().onmouseout=function(){this.quickFind.menu.isFocused=false;}
this.getButton().onclick=function(){
if(this.disabled)return;
var item=this.quickFind.getCheckBoxList().getItem(this.selectedValue);
item.select(true);
if(item.isSelected()&&this.quickFind.focusSelectedItem){
if(item.folder!=null)item.folder.open();
this.quickFind.getCheckBoxList().scrollItemToTop(item);
}
this.quickFind.clear();
this.quickFind.getTextBox().focus();
}
}
var quickFind=this;
this.getCheckBoxList().addChangeEventHandler(function(sender){quickFind.text=null;});
}
TwoTierCheckBoxList_QuickFind.prototype.render=function(){
if(this.text!=this.getTextBox().value){
this.text=this.getTextBox().value;
this.disableButton();
if(this.text!=null&&this.text.length>0&&this.text!=this.defaultText){
var items=this.getCheckBoxList().find(this.text);
this.menu.clear();
if(items.length>0){
for(var i=0;i<items.length&&i<this.maxFindResults;i++){
var text=items[i].name.replace(items.regularExpression,"<b>$1</b>");
if(items.duplicates[items[i].name]==true&&items[i].folder!=null){
text+=" ("+items[i].folder.name+")";
}
this.menu.addItem(items[i].value,items[i].name,text);
}
this.menu.show();
this.menu.render();
if(this.getButton()!=null){
if(items.length==1&&items[0].name.toLowerCase()==this.text.toLowerCase()){
this.getButton().selectedValue=items[0].value;
this.enableButton();
}
else{
this.getButton().selectedValue="";
this.disableButton();
}
}
}
else if(this.noMatchText!=null&&this.noMatchText.length>0){
this.menu.show();
this.menu.getElement().innerHTML="<div class=\"NoMatch\">"+this.noMatchText+"</div>";
}
}
else{
this.menu.hide();
}
}
}
function TwoTierCheckBoxList_QuickFind_Menu(name,id){
this.name=name;
this.id=id;
this.clear();
if(window[name]==null)window[name]=this;
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.clear=function(){
this.items=new Array();
this.selectedItemIndex=-1;
this.focusedItemIndex=-1;
this.getElement().innerHTML="";
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.addItem=function(value,name,text){
this.items.push(new TwoTierCheckBoxList_QuickFind_MenuItem(value,name,text,this.items.length,this.id));
if(this.focusedItemIndex=-1)this.focusedItemIndex=0;
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.getElement=function(){
if(this.element==null){
this.element=document.getElementById(this.id);
}
return this.element;
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.getSelectedItem=function(){
if(this.selectedItemIndex>=0&&this.selectedItemIndex<this.items.length){
return this.items[this.selectedItemIndex];
}
return null;
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.render=function(){
var html=new Array();
for(var i=0;i<this.items.length;i++){
this.items[i].render(html);
}
this.getElement().innerHTML=html.join("\n");
this.attachEvents();
this.focus(0);
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.attachEvents=function(){
this.getElement().onmouseover=new Function(this.name+".isFocused = true;");
this.getElement().onmouseout=new Function(this.name+".isFocused = false;");
for(var i=0;i<this.items.length;i++){
this.items[i].getElement().onmouseover=new Function(this.name+".focus("+i+");"+this.name+".focusChanged("+this.name+".items[ "+i+" ] );");
this.items[i].getElement().onclick=new Function(this.name+".select();");
}
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.focus=function(index){
if(this.items.length>0){
if(index<0)index=0;
if(index>=this.items.length)index=this.items.length-1;
this.blur(this.focusedItemIndex);
this.focusedItemIndex=index;
this.items[index].focus();
}
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.blur=function(index){
if(index>=0&&index<this.items.length){
this.items[index].blur();
}
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.hide=function(){
this.getElement().style.display="none";
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.show=function(){
this.getElement().style.display="";
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.isVisible=function(){
return(this.getElement().style.display!="none");
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.moveUp=function(){
this.focus(this.focusedItemIndex-1);
this.focusChanged(this.items[this.focusedItemIndex]);
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.moveDown=function(){
this.focus(this.focusedItemIndex+1);
this.focusChanged(this.items[this.focusedItemIndex]);
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.focusChanged=function(selectedItem){
}
TwoTierCheckBoxList_QuickFind_Menu.prototype.select=function(){
this.selectedItemIndex=this.focusedItemIndex;
if(this.onSelect!=null){
this.onSelect(this,this.getSelectedItem());
}
this.hide();
}
function TwoTierCheckBoxList_QuickFind_MenuItem(value,name,text,index,parentID){
this.value=value;
this.name=name;
this.text=text;
this.index=index;
this.parentID=parentID;
}
TwoTierCheckBoxList_QuickFind_MenuItem.prototype.getID=function(){
return this.parentID+":"+this.index;
}
TwoTierCheckBoxList_QuickFind_MenuItem.prototype.getElement=function(){
if(this.element==null){
this.element=document.getElementById(this.getID());
}
return this.element;
}
TwoTierCheckBoxList_QuickFind_MenuItem.prototype.render=function(html){
html.push("<div class=\"Item\" id=\""+this.getID()+"\">"+this.text+"</div>");
}
TwoTierCheckBoxList_QuickFind_MenuItem.prototype.focus=function(){
this.getElement().className="Item MouseOver";
}
TwoTierCheckBoxList_QuickFind_MenuItem.prototype.blur=function(){
this.getElement().className="Item";
}
function TwoTierCheckBoxList_SelectionValidator(errorMessage,maxItems,maxFolders,maxItemsInFolder){
this.errorMessage=errorMessage;
this.maxItems=maxItems!=null?maxItems:0;
this.maxFolders=maxFolders!=null?maxFolders:0;
this.maxItemsInFolder=maxItemsInFolder!=null?maxItemsInFolder:0;
}
TwoTierCheckBoxList_SelectionValidator.prototype.validate=function(checkBoxList){
var result=true;
var selection=checkBoxList.getSelection();
if(this.maxItems>0)result=result&&(selection.itemCount<=this.maxItems);
if(result&&this.maxFolders>0)result=result&&(selection.folders.length<=this.maxFolders);
if(result&&this.maxItemsInFolder>0){
for(var i=0;i<selection.folders.length;i++){
result=result&&(selection.folders[i].items.length<=this.maxItemsInFolder);
if(!result)break;
}
}
return result;
}
TwoTierCheckBoxList_SelectionValidator.prototype.execute=function(checkBoxList,item){
var changed=false;
checkBoxList.getSelection();
if(item==null||item.isSelected()){
if(item==null){
checkBoxList.iterateItems(function(item){if(item.isDisabled())item.enable();});
}
if(this.maxItems>0&&checkBoxList.getSelection().itemCount>=this.maxItems){
checkBoxList.iterateItems(function(item){if(!item.isSelected())item.disable();});
changed=true;
}
if(this.maxFolders>0&&checkBoxList.getSelection().folders.length>=this.maxFolders){
checkBoxList.iterateFolders(function(folder){if(folder.selectedItemsCount==0)folder.disable();});
changed=true;
}
if(this.maxItemsInFolder>0){
if(item==null){
checkBoxList.iterateFolders(new Function("folder","if ( folder.selectedItemsCount >= "+this.maxItemsInFolder+" ) folder.disable();"));
changed=true;
}
else if(item.folder!=null&&item.folder.selectedItemsCount>=this.maxItemsInFolder){
item.folder.disable();
changed=true;
}
}
if(changed)this.onDisable();
}
else{
if(item.folder!=null&&this.maxItemsInFolder>0&&item.folder.selectedItemsCount==(this.maxItemsInFolder-1)){
item.folder.enable();
changed=true;
}
if(item.folder!=null&&this.maxFolders>0&&item.folder.selectedItemsCount==0&&checkBoxList.getSelection().folders.length==(this.maxFolders-1)){
if(this.maxItemsInFolder==0){
checkBoxList.iterateFolders(function(folder){folder.enable();});
}
else{
var maxItemsInFolder=this.maxItemsInFolder;
checkBoxList.iterateFolders(function(folder){if(folder.selectedItemsCount<maxItemsInFolder)folder.enable();});
}
changed=true;
}
if(this.maxItems>0&&checkBoxList.getSelection().itemCount==(this.maxItems-1)){
changed=true;
checkBoxList.iterateItems(function(item){if(item.folder==null)item.enable();});
if(this.maxFolders==0&&this.maxItemsInFolder==0){
checkBoxList.iterateFolders(function(folder){folder.enable();});
}
else if(this.maxFolders==0){
var maxItemsInFolder=this.maxItemsInFolder;
checkBoxList.iterateFolders(function(folder){if(folder.selectedItemsCount<maxItemsInFolder)folder.enable();});
}
else if(this.maxItemsInFolder==0){
if(checkBoxList.getSelection().folders.length<this.maxFolders){
checkBoxList.iterateFolders(function(folder){folder.enable();});
}
else{
checkBoxList.iterateFolders(function(folder){if(folder.selectedItemsCount>0)folder.enable();});
}
}
else{
var maxItemsInFolder=this.maxItemsInFolder;
if(checkBoxList.getSelection().folders.length<this.maxFolders){
checkBoxList.iterateFolders(function(folder){if(folder.selectedItemsCount<maxItemsInFolder)folder.enable();});
}
else{
checkBoxList.iterateFolders(function(folder){if(folder.selectedItemsCount>0&&folder.selectedItemsCount<maxItemsInFolder)folder.enable();});
}
}
}
if(changed)this.onEnable();
}
}
TwoTierCheckBoxList_SelectionValidator.prototype.onDisable=function(){}
TwoTierCheckBoxList_SelectionValidator.prototype.onEnable=function(){}
function TwoTierCheckBoxList_ClearAll(checkBoxListName){
this.checkBoxListName=checkBoxListName;
if(getCheckBoxList()!=null)
{
getCheckBoxList().clearSelection();
}
}
function getCheckBoxList(){return window[this.checkBoxListName];}
